using System;
using System.Collections.Generic;
using System.Text;
using Bussiness.Data;
using DataProvider;
using System.Data;
using System.Data.SqlClient;
using Bussiness.Exc;

namespace Bussiness.Interfaces
{
    public class LOAIKTRAProcess:ILOAIKTRA
    {
        IDBManager idbManager = new DBManager(DataProviderE.SqlServer);

        DataTable ILOAIKTRA.XemLOAIKTRA()
        {
            DataTable tbl = null;
            try
            {
                idbManager.Open();
                tbl = idbManager.ExecuteDataSet(CommandType.StoredProcedure, "spLOAIKTRAXem").Tables[0];
            }
            catch (DatabaseExc e)
            {
                throw new BussinessExc(e.Message, e.ErrCodeUser, e.ErrCodeSQL);
            }
            catch (Exception e)
            {
                throw new BussinessExc("Bussiness. ILOAIKTRA.XemLOAIKTRA()" + e.Message);
            }
            finally
            {
                idbManager.Dispose();
            }
            return tbl;
        }
        bool ILOAIKTRA.ThemLOAIKTRA(LOAIKTRA loaiKTra)
        {
            bool success = false;
            try
            {
                idbManager.CreateParameters(4);
                idbManager.AddParameters(0, "@Hocky", loaiKTra.HocKy, ParameterDirection.Input);
                idbManager.AddParameters(1, "@Makt", loaiKTra.MaKT, ParameterDirection.Input);
                idbManager.AddParameters(2, "@Tenkt", loaiKTra.TenKT, ParameterDirection.Input);
                idbManager.AddParameters(3, "@Heso", loaiKTra.HeSo, ParameterDirection.Input);
                idbManager.Open();
                int isuccess = idbManager.ExecuteNonQuery(CommandType.StoredProcedure, "spLOAIKTRAThem");
                if (isuccess > 0)
                    success = true;
            }
            catch (DatabaseExc e)
            {
                throw new BussinessExc(e.Message, e.ErrCodeUser, e.ErrCodeSQL);
            }
            catch (Exception e)
            {
                throw new BussinessExc("Bussiness. ILOAIKTRA.ThemLOAIKTRA(LOAIKTRA loaiKTra)" + e.Message);
            }
            finally
            {
                idbManager.Dispose();
            }
            return success;
        }
        bool ILOAIKTRA.XoaLOAIKTRA(byte hockyValue,string maKTraValue)
        {
            bool success = false;
            try
            {
                idbManager.CreateParameters(2);
                idbManager.AddParameters(0, "@Hocky", hockyValue, ParameterDirection.Input);
                idbManager.AddParameters(1, "@Makt", maKTraValue, ParameterDirection.Input);
                idbManager.Open();
                int isuccess = idbManager.ExecuteNonQuery(CommandType.StoredProcedure, "spLOAIKTRAXoa");
                if (isuccess > 0)
                    success = true;
            }
            catch (DatabaseExc e)
            {
                throw new BussinessExc(e.Message, e.ErrCodeUser, e.ErrCodeSQL);
            }
            catch (Exception e)
            {
                throw new BussinessExc("Bussiness. ILOAIKTRA.XoaLOAIKTRA(string maKTraValue)" + e.Message);
            }
            finally
            {
                idbManager.Dispose();
            }
            return success;
        }
        bool ILOAIKTRA.UpdateLOAIKTRA(LOAIKTRA loaiKTra)
        {
            bool success = false;
            try
            {
                idbManager.CreateParameters(4);
                idbManager.AddParameters(0, "@Hocky", loaiKTra.HocKy, ParameterDirection.Input);
                idbManager.AddParameters(1, "@Makt", loaiKTra.MaKT, ParameterDirection.Input);
                idbManager.AddParameters(2, "@Tenkt", loaiKTra.TenKT, ParameterDirection.Input);
                idbManager.AddParameters(3, "@Heso", loaiKTra.HeSo, ParameterDirection.Input);
                idbManager.Open();
                int isuccess = idbManager.ExecuteNonQuery(CommandType.StoredProcedure, "spLOAIKTRAUpdate");
                if (isuccess > 0)
                    success = true;
            }
            catch (DatabaseExc e)
            {
                throw new BussinessExc(e.Message, e.ErrCodeUser, e.ErrCodeSQL);
            }
            catch (Exception e)
            {
                throw new BussinessExc("Bussiness. ILOAIKTRA.UpdateLOAIKTRA(LOAIKTRA loaiKTra)" + e.Message);
            }
            finally
            {
                idbManager.Dispose();
            }
            return success;
        }
    }
}
